package com.leisai.manager.common.utils;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class IndutryConfigUtils {

   public static   Map<String , Object> getElement(String tagName) {
       try {

        Map<String ,Object> map = new HashMap<>();
        //1.创建Reader对象
        SAXReader reader = new SAXReader();
        //2.加载xml
        Document document = reader.read(new File("src/main/resources/config/industryConfig.xml"));
        //3.获取根节点
        Element rootElement = document.getRootElement();
        Iterator iterator = rootElement.elementIterator();
        while (iterator.hasNext()){
            Element stu = (Element) iterator.next();
            if (stu.getName().equalsIgnoreCase(tagName)){
                List<Attribute> attributes = stu.attributes();
                Iterator iterator1 = stu.elementIterator();
                while (iterator1.hasNext()){
                    Element stuChild = (Element) iterator1.next();
                    map.put(stuChild.getName(),stuChild.getStringValue());
                }
                break;
            }
        }
           return map;
       }catch (Exception e){
           e.printStackTrace();
       }
       return null;
    }
 }
